Spring Boot Starter Web 您所在的位置:网站首页 spring boot 230 Spring Boot Starter Web

Spring Boot Starter Web

2023-04-11 21:13| 来源: 网络整理| 查看: 265

spring-boot-starter-web有两个重要功能:

与Web开发兼容自动配置

如果要开发Web应用程序,则需要在pom.xml文件中添加以下依赖项:

org.springframework.boot spring-boot-starter-web 2.2.2.RELEASE

Spring Web Starter使用Spring MVC,REST和Tomcat作为默认的嵌入式服务器。 单个spring-boot-starter-web依赖关系可传递地获取与Web开发相关的所有依赖关系。 它还减少了构建依赖项计数。 spring-boot-starter-web可传递地取决于以下内容:

org.springframework.boot:spring-boot-starterorg.springframework.boot:spring-boot-starter-tomcatorg.springframework.boot:spring-boot-starter-validationcom.fasterxml.jackson.core:jackson-databindorg.springframework:spring-weborg.springframework:spring-webmvc

默认情况下,spring-boot-starter-web包含以下tomcat服务器依赖项:

org.springframework.boot spring-boot-starter-tomcat 2.0.0.RELEASE compile

spring-boot-starter-web自动配置Web开发所需的以下各项:

Dispatcher Servlet错误页面用于管理静态依赖项的Web JAR嵌入式Servlet容器 1.Spring Boot嵌入式Web服务器

每个Spring Boot应用程序都包含一个嵌入式服务器。 嵌入式服务器被嵌入为可部署应用程序的一部分。 嵌入式服务器的优点是,我们不需要在环境中预安装服务器。 使用Spring Boot,默认的嵌入式服务器是Tomcat。 Spring Boot还支持另外两个嵌入式服务器:

Jetty ServerUndertow Server

使用另一个嵌入式Web服务器

对于servlet堆栈应用程序,spring-boot-starter-web通过包含spring-boot-starter-tomcat来包括Tomcat,但是可以改用spring-boot-starter-jetty或spring-boot-starter-undertow。

对于反应堆应用程序,spring-boot-starter-webflux通过包含spring-boot-starter-reactor-netty来包含Reactor Netty,但是我们可以使用spring-boot-starter-tomcat,spring-boot-starter-jetty或spring -boot-starter-undertow代替。

Jetty服务器

Spring Boot还支持称为Jetty Server的嵌入式服务器。 它是一个HTTP服务器和Servlet容器,具有提供静态和动态内容的功能。 需要机器间通信时使用。

如果要在应用程序中添加Jetty服务器,则需要在pom.xml文件中添加spring-boot-starter-jetty依赖项。

切记:在应用程序中使用Jetty服务器时,请确保从spring-boot-starter-web中排除了默认的Tomcat服务器。 它避免了服务器之间的冲突。

org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat org.springframework.boot spring-boot-starter-undertow

还可以使用application.properties文件来自定义Undertow服务器的行为。

2.spring-boot-starter-web与spring-boot-starter-tomcat

spring-boot-starter-web包含spring网络依赖关系,其中包括spring-boot-starter-tomcat。 spring-boot-starter-web包含以下内容:

spring-boot-starterjacksonspring-corespring-mvcspring-boot-starter-tomcat

而spring-boot-starter-tomcat包含与Tomcat服务器相关的所有内容。它们如下:

coreelloggingwebsocket

starter-tomcat具有以下依赖性:

org.apache.tomcat.embed tomcat-embed-core 8.5.23 compile org.apache.tomcat.embed tomcat-embed-el 8.5.23 compile org.apache.tomcat.embed tomcat-embed-websocket 8.5.23 compile

也可以不使用嵌入式Tomcat服务器而使用spring-mvc。 如果要这样做,需要使用标记排除Tomcat服务器,如以下代码所示:

org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat

  

上一篇: Spring Boot保护Web应用程序 下一篇:哥,这回真没有了


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有